<template>
	<div>
	<el-form :inline="true" size="mini">
		<el-form-item>
			<el-button type="primary" @click="disableAddDept=true">新增楼层</el-button>
		</el-form-item>
	</el-form>
	<div slot="footer">
		<el-button type="danger" size="mini" :disabled="ids.length==0" @click="batchDelete">批量删除</el-button>
	
	</div>
		<el-table :data="pageInfo" style="100%" @selection-change="handleSelectionChange">
			<el-table-column type="selection"></el-table-column>
			<el-table-column
			label="编号"
			prop="id"
			width="80"
			></el-table-column>
			<el-table-column label="楼层" width="200">
				<template slot-scope="scope">
					<template v-if="scope.row.edit" >
						<el-input v-model="type.storey" size="mini"></el-input>
					</template>
					<template >
						<span>{{scope.row.storey}}</span>
					</template>
				</template>
			</el-table-column>
			<el-table-column label="标记" width="200">
				<template slot-scope="scope">
					<template  v-if="scope.row.edit" >
						<el-input v-model="type.delmark" size="mini"></el-input>
					</template>
					<template >
						<span>{{scope.row.delmark}}</span>
					</template>
				</template>
			</el-table-column>
			
			<el-table-column label="操作" width="300">
				<template slot-scope="scope">
					<template v-if="scope.row.edit">
						<el-button @click="handleTypeSave(scope)" size="mini">保存</el-button>
						<el-button size="mini" @click="scope.row.edit=false">取消</el-button>
					</template>
					<template v-else>
						<el-button @click="handleTypeEdit(scope)" size="mini">编辑</el-button>
						<el-button size="mini" @click="handleTypeDel(scope)">删除</el-button>
					</template>					
				</template>
			</el-table-column>
		</el-table>
		
		
		
		<el-dialog :visible.sync="disableAddDept" title="新增楼层" center>
			<el-form :inline="true" aligin="center" size="mini">
				<el-form-item label="编码">
					<el-input v-model="type.id" placeholder="编码"></el-input>
				</el-form-item>
				<el-form-item label="楼层">
					<el-input v-model="type.storey"  placeholder="楼层"></el-input>
				</el-form-item>
				   <el-form-item label="标记">
				         <el-input placeholder="标记" v-model="type.delmark"></el-input>     
				       </el-form-item>
				<el-form-item>
					<el-button type="warning" @click="disableAddDept=false">取消</el-button>
					<el-button type="primary" @click="insertType()">保存</el-button>
				</el-form-item>
			</el-form>
			
			
		</el-dialog>
	</div>
	
</template>

<script>
	export default{
		data(){
			return{
				pageInfo:[],
				type:{},
				keyword:'',
				disableAddDept:false,
				
				params:{},
				typeList:{},
				ids:[]
			}
			
		},
		created() {
			this.show();
			
		},
		methods:{
			show(){
				let url = "Storey/getAll";
				axios.post(url).then(resp=>{
					this.pageInfo = resp.data.data;	
				});
			},
			insertType(){
				let url = "Storey/insert";
				axios.post(url,this.type).then(resp=>{
					if(resp.data.data == 1){
						this.$alert("添加成功");
						this.disableAddDept = false;
						console.log(this.type);
						this.show();
					}
				});
			},
			handleTypeEdit(scope){
				//console.log(scope.$index,scope.row);
				this.$set(scope.row,"edit",true);
				//对象克隆
				this.type = {...scope.row};
			},
			handleTypeSave(scope){
				let url = "Storey/update";
				axios.post(url,this.type).then(resp=>{
					if(resp.data.data == 1){	
						scope.row.edit = false;
						scope.row.id = this.type.id;
						scope.row.storey = this.type.storey;
						scope.row.delmark = this.type.delmark;
						
					}
					this.show();
				});
			},
			handleTypeDel(scope){
				this.$confirm("是否删除","提示").then(()=>{
					let url = "Storey/delete";
					axios.post(url,`id=${scope.row.id}`).then(resp=>{
						if(resp.data.data == 1){
							this.$alert("删除成功！");
							this.show();
						}
					});
				}).catch(()=>{
					console.log("cancel");
				});
				
			},
			handleSelectionChange(item){
				this.ids = item.map(o=>o.id);
			},
			//批量删除
			batchDelete(){
				this.$confirm("是否删除?","提示").then(()=>{
					let url = "Storey/batchDelete";
					
					axios.post(url,this.ids).then(resp=>{
						if(resp.data.data > 0){
							this.$alert("删除成功！");
							this.show();
						}
					});
				}).catch(err=>{
					this.$alert(err);
				});
			}/* ,
			AddDept(){
				this.disableAddDept = true;
				let url = "goodsmanage/insert";
				
				axios.post(url).then(resp=>{
					this.typeList = resp.data.data;
					//console.log(this.typeList);
				});
			} */
		}
		
		
	}
</script>

<style>
</style>
